// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) KALEIDOS INC

@use "ds/_borders.scss" as *;
@use "ds/_sizes.scss" as *;
@use "ds/typography.scss" as *;
@use "ds/colors.scss" as *;

.input-wrapper {
  --input-bg-color: var(--color-background-tertiary);
  --input-fg-color: var(--color-foreground-primary);
  --input-icon-color: var(--color-foreground-secondary);
  --input-outline-color: none;
  --input-height: #{$sz-32};
  --input-margin: unset;

  display: inline-flex;
  column-gap: var(--sp-xs);
  align-items: center;
  position: relative;
  inline-size: 100%;

  background: var(--input-bg-color);
  border-radius: $br-8;
  padding: 0 var(--input-padding-size, var(--sp-s));
  outline: $b-1 solid var(--input-outline-color);

  &:hover {
    --input-bg-color: var(--color-background-quaternary);
  }

  &:has(*:focus-visible) {
    --input-bg-color: var(--color-background-primary);
    --input-outline-color: var(--color-accent-primary);
  }

  &:has(*:disabled) {
    --input-bg-color: var(--color-background-primary);
    --input-outline-color: var(--color-background-quaternary);
  }
}

.variant-dense,
.variant-seamless {
  @include use-typography("body-small");
}

.variant-comfortable {
  @include use-typography("body-medium");
}

.variant-seamless {
  --input-bg-color: none;
  --input-outline-color: none;
  --input-height: auto;
  --input-margin: 0;

  padding: 0;
  border: none;

  &:hover {
    --input-bg-color: none;
    --input-outline-color: none;
  }

  &:has(*:focus-visible) {
    --input-bg-color: none;
    --input-outline-color: none;
  }
}

.input {
  margin: var(--input-margin); // remove settings from global css
  padding: 0;
  appearance: none;
  height: var(--input-height);
  border: none;
  background: none;
  inline-size: 100%;

  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;

  color: var(--input-fg-color);

  &:focus-visible {
    outline: none;
  }

  &::selection {
    background: var(--color-accent-select);
  }

  &::placeholder {
    --input-fg-color: var(--color-foreground-secondary);
  }

  &:is(:autofill, :autofill:hover, :autofill:focus, :autofill:active) {
    -webkit-text-fill-color: var(--input-fg-color);
    -webkit-background-clip: text;
    background-clip: text;
    caret-color: var(--input-bg-color);
  }
}

.input-with-icon {
  margin-inline-start: var(--sp-xxs);
}

.hint-type-error {
  --input-outline-color: var(--color-foreground-error);
}

.icon {
  color: var(--color-foreground-secondary);
}
